package es

import (
	"github.com/olivere/elastic/v7"
)

//  -------------------------------------------- Must -------------------------------------------
// Term in Must
func (m *Model) MustTerm(fieldName string, value interface{}) *Model {
	return m.AddMust(elastic.NewTermQuery(fieldName, value))
}

// Term in Must
func (m *Model) MustTerms(fieldName string, values ...interface{}) *Model {
	return m.AddMust(elastic.NewTermsQuery(fieldName, values...))
}

// Match in Must
func (m *Model) MustMatch(fieldName string, value interface{}) *Model {
	return m.AddMust(elastic.NewMatchQuery(fieldName, value))
}

// MatchPhrase in Must
func (m *Model) MustMatchPhrase(fieldName string, value interface{}) *Model {
	return m.AddMust(elastic.NewMatchPhraseQuery(fieldName, value))
}

// QueryString in Must
func (m *Model) MustQueryString(fieldName string, value string) *Model {
	return m.AddMust(elastic.NewQueryStringQuery(value).DefaultField(fieldName))
}

// Regexp in Must
func (m *Model) MustRegexp(fieldName string, value string) *Model {
	return m.AddMust(elastic.NewRegexpQuery(fieldName, value))
}

// Wildcard in Must
func (m *Model) MustWildcard(fieldName string, value string) *Model {
	return m.AddMust(elastic.NewWildcardQuery(fieldName, value))
}

// Script in Must
func (m *Model) MustScript(fieldName string, value string) *Model {
	return m.AddMust(elastic.NewScriptQuery(elastic.NewScript(value)).QueryName(fieldName))
}

// Range in Must
func (m *Model) MustRange(fieldName string, rangeOptions ...RangeOption) *Model {
	r := elastic.NewRangeQuery(fieldName)
	for _, rangeOption := range rangeOptions {
		rangeOption(r)
	}
	return m.AddMust(r)
}

// Exist in Must
func (m *Model) MustExist(fieldName string) *Model {
	return m.AddMust(elastic.NewExistsQuery(fieldName))
}
